package com.leetcode.hash;

import java.util.HashMap;

/**
 * @author Dennis Li
 * @date 2020/7/19 20:43
 */
public class FindLHS_594 {

    public int findLHS(int[] nums) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            // 将对应位置加一
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        int max = 0;
        for (int num : nums) {
            if(map.containsKey(num - 1))
                max = Math.max(max, map.get(num) + map.get(num - 1));
        }
        return max;
    }

}
